
#ifndef __ENCMESSAGE_H
#define __ENCMESSAGE_H

#include <vector>
#include <stdarg.h>
#include <apr-1/apr_pools.h>
#include <apr-1/apr_tables.h>

class EncMessage
{
   public:
      EncMessage(apr_pool_t *imp);
      ~EncMessage();

      void ReplyTo(EncMessage *imsg);
      void SetRecipient(const char *iformat, ...);
      void SetSender(const char *iformat, ...);
      void AddTypeHeaderNOCRLF(const char *itype, const char *iprocessee);
      void AddHeaderLineNOCRLF(const char *iformat, ...);
      void AddPayloadString(const char *iformat, ...);
      void AddVerbatimPayloadString(const char *istring);
      void AddPayloadBuffer(const char *ibuffer, int ilength);
      void ForceNoSignature();
      void ForceDestroySendingKey();

      void Reset();

      void SetWasSignedFlag();
      void ParseHeaderStream(const char *stream);
      void GenerateHeaderTable();
      const char *GetHeaderStream();

      const char *GetRecipient();
      const char *GetSender();
      const char *GetType();
      const char *GetProcessee();
      const int GetHowManyPayloads();
      const char *GetPayload(int pnum);
      const int GetPayloadLength(int pnum);
      const int IsType(const char *ctype);
      const int IsPayloadCount(const int pcount);
      const int WeMustDestroySendingKey();
      const int GuaranteedAuthentic();
      const int ToBeSigned();

      apr_pool_t *GetEncMessageAssociatedMemoryPool();
      const apr_table_t *GetHeaderTable();
      const apr_table_t *GetAuxHeaderTable(int payload, const char *linesep, const char *keyvalsep);
      const int GetAuxHeaderCount();

      void Print();
      int IsBinary(const char *bindata, int length);
      void PrintHex(const char *bindata, int length);
   protected:
      apr_pool_t *highmp;
      apr_pool_t *mp;
      const char *recipient, *sender;
      apr_table_t *htable;
      apr_table_t *aux_htable;
      const char *messagetype, *processee;
      std::vector<const char *> *headers;
      std::vector<const char *> *aux_headers;
      std::vector<const char *> *payloads;
      std::vector<int> *lengths;
      int willsign;
      int issigned;
      int removesendingkey;
};

#endif
